﻿using AiBLSmartEdu.Module.AIHealthManage.API.DTOs;
using AiBLSmartEdu.Module.AIHealthManage.API.Services;
using Domain.Entities;
using FrameworkCore;
using FrameworkCore.Controllers;
using FrameworkCore.Helpers;
using FrameworkCore.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AiBLSmartEdu.Module.AIHealthManage.API.Controllers
{
    /// <summary>
    /// 健康管理AI助手
    /// </summary>
    [AllowAnonymous]
    public class AIHealthManageController : BaseModuleController
    {
       private readonly HealthRecordService _healthRecordService;

        public AIHealthManageController(
            HealthRecordService healthRecordService)
        {
            _healthRecordService = healthRecordService;
        }

        /// <summary>
        /// 健康记录分页查询
        /// </summary>
        /// <param name="filter">分页输入模型</param>
        /// <returns></returns>
        [HttpGet("Page")]
        public async Task<PageResult<HealthRecordOutputModel>> PaginationAsync([FromQuery] HealthRecordPaginationFilter filter)
        {
            return await _healthRecordService.PageAsync(filter);
        }

        /// <summary>
        /// 创建健康记录
        /// </summary>
        /// <param name="model">输入模型</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<long>> CreateAsync(HealthRecordCreateInputModel model)
        {        
            return await Result<long>.SucceedAsync(await _healthRecordService.CreateAsync(model));
        }

        /// <summary>
        /// 获取一条健康记录
        /// </summary>
        /// <param name="id">输入模型</param>
        /// <returns></returns>
        [HttpGet("{id}")]
        public async Task<Result<HealthRecordOutputModel>> GetByIdAsync(long id)
        {
            return await Result<HealthRecordOutputModel>.SucceedAsync(await _healthRecordService.GetByIdAsync(id));
        }

        /// <summary>
        /// 获取诊断结果
        /// </summary>
        /// <param name="id">健康记录ID</param>
        /// <param name="isRediagnose">是否重新诊断</param>
        /// <returns></returns>
        [HttpGet("Resuts/{id}/{isRediagnose?}")]
        public async Task<Result<HealthRecordOutputModel>> GetResutsByIdAsync(long id, bool? isRediagnose = false)
        {
            return await Result<HealthRecordOutputModel>.SucceedAsync(await _healthRecordService.GetResutsByIdAsync(id, isRediagnose));
        }

        /// <summary>
        /// 删除健康记录
        /// </summary>
        /// <param name="id">输入模型</param>
        /// <returns></returns>
        [HttpDelete("{id}")]
        public async Task<Result> DeleteAsync(long id)
        {
            await _healthRecordService.DeleteAsync(id);
            return await Result.SucceedAsync();
        }
    }
}
